<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>无标题文档</title>
		<link href="http://127.0.0.1/vancl/Static/Admin/css/style.css" rel="stylesheet" type="text/css" />
		<link href="http://127.0.0.1/vancl/Static/Admin/css/select.css" rel="stylesheet" type="text/css" />
		
		<link href="http://127.0.0.1/vancl/Static/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
		<link href="http://127.0.0.1/vancl/Static/Flat/dist/css/flat-ui.css" rel="stylesheet">
			
		<script type="text/javascript" src="http://127.0.0.1/vancl/Static/uploadify/jquery-1.8.2.min.js"></script>
		<script type="text/javascript" charset="utf-8" src="http://127.0.0.1/vancl/Static/ueditor1_4_3/ueditor.config.js"></script>
	    <script type="text/javascript" charset="utf-8" src="http://127.0.0.1/vancl/Static/ueditor1_4_3/ueditor.all.min.js"></script>
	    <script type="text/javascript" charset="utf-8" src="http://127.0.0.1/vancl/Static/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>

		<script type="text/javascript" src="http://127.0.0.1/vancl/Static/hdjs/hdjs.min.js"></script>
		<link rel="stylesheet" type="text/css" href="http://127.0.0.1/vancl/Static/hdjs/hdjs.css"/>
		<script type="text/javascript" src="http://127.0.0.1/vancl/Static/Admin/js/select-ui.min.js"></script>		
		<script type="text/javascript" src="http://127.0.0.1/vancl/Static/uploadify/jquery.uploadify.min.js"></script>
		<link rel="stylesheet" type="text/css" href="http://127.0.0.1/vancl/Static/uploadify/uploadify.css" />
		

		<style type="text/css">
			.forminfo li label{
				padding-right: 10px;
				text-align: right;
			}
			
			#uploadList ul li .img{
				width: 200px;
			}			
			
			#albumUploadList ul li {
				float: left;
				margin-right: 40px;
			}
			
			#albumUploadList ul li .img{
				width: 200px;
			} 
			
			.a_del_li_album img{
				position: absolute;
				right:-28px;
				top: 6px;
			}
			
			#desc p,#desc body,#desc br, #desc span{
				display: inline;
			}
			
			#uploadIndexList ul li{
				list-style: none;
				float: left;
				margin-right: 10px;
				position: relative;
				border: 1px solid #CCC;
			}
			#a_del_li_indexPic img{
				position: absolute;
				right:-28px;
				top: 6px;
			}
			#uploadIndexTip{
				float:left;
				line-height: 34px;
			}
			
			#uploadIndexList ul li .img{
				width: 200px;
			}	
		</style>
		<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
		<style type="text/css">
			#uploadList ul li{
				list-style: none;
				float: left;
				margin-right: 10px;
				position: relative;
				border: 1px solid #CCC;
			}
			#a_del_li img{
				position: absolute;
				right:-28px;
				top: 6px;
			}
			#uploadTip{
				float:left;
				line-height: 34px;
			}
		</style>
		
		<style type="text/css">
			.uploadList ul li{
				list-style: none;
				float: left;
				clear: none;
				margin-right: 10px;
				position: relative;
				border: 1px solid #CCC;
			}
			.a_del_li img{
				position: absolute;
				right:-28px;
				top: 6px;
			}
			.uploadTip{
				float:left;
				line-height: 34px;
			}
		</style>
		
		<script type="text/javascript">
			function showUploadify(varName){
				fileVarName = varName;
				$('#file').uploadify({
			        'formData': {
			        		//POST数据
			            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			        },
			        'fileTypeDesc' : '上传文件',
			        'fileTypeExts' : '<?php echo $set['filetype'];?>',
			        'swf'      : 'http://127.0.0.1/vancl/Static/uploadify/uploadify.swf',
			        'uploader' : '<?php echo U("ajaxUpload");?>',
			        'buttonText':'选择文件',
			        'fileSizeLimit' : '2000KB',
			        'uploadLimit' : 1,//上传文件数
			        'multi': false,
			        'width':65,
			        'height':25,
			        'successTimeout':10,//等待服务器响应时间
			        'removeTimeout' : 0.2,//成功显示时间
			        'onUploadSuccess' : function(file, data, response) {
			            data=$.parseJSON(data);
			            var imageUrl = data.image?data.url:'http://127.0.0.1/vancl/Static/image/default.png';
			            var li="<li path='"+data.path+"' url='"+data.url+"'>" +
			            				"<img class='img' src='" + imageUrl + "'/>" +
			            				"<a id='a_del_li' href='javascript:;' title='删除'>" + 
			            					"<img src='http://127.0.0.1/vancl/Static/Admin/images/close1.png'/>" + 
			            				"</a>" + 
			            				"<input type='hidden' name='" + varName + "' value='" + data.path+"'/>" + 
			            			"</li>";
			            $("#uploadList ul").prepend(li);
			            $("#uploadDiv").html('');
			            $('#uploadTip').hide();
			        }
			    });
			}
			
			$(function() {
			    $('#a_del_li').live('click', function(){
			    		if (!confirm('确定要删除吗？')){
			    			return;
			    		}
			    		$("#uploadList ul li").remove();
			    		var str = "<input id='file' type='file' multiple='true'>";
			
			    		$("#uploadDiv").html(str);
			    		$('#uploadTip').show();
					showUploadify(fileVarName);	
			    });
			});
		</script>
		
		<script type="text/javascript">
			function showAlbumUploadify(varName, url, staticPath, fileType, sessionName, sessionId){
				albumfileVarName = varName;
				staticPathVar = staticPath;
				
				$('#albumfile').uploadify({
			        'formData': {
			        		//POST数据
			            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			        },
			        'fileTypeDesc' : '上传文件',
			        'fileTypeExts' : fileType,
			         'swf': staticPathVar + '/uploadify/uploadify.swf',
			        'uploader' : url,
			        'buttonText':'选择文件',
			        'fileSizeLimit' : '2000KB',
			        'uploadLimit' : 20,//上传文件数
			        'multi': true,
			        'width':65,
			        'height':25,
			        'successTimeout':10,//等待服务器响应时间
			        'removeTimeout' : 0.2,//成功显示时间
			        'onUploadSuccess' : function(file, data, response) {
			            data=$.parseJSON(data);
			            var li="<li path='"+data.path+"' url='"+data.url+"'>" +
			            				"<img class='img' src='" + data.url + "' class='hd-w70 hd-h30'/>" +
			            				"<a class='a_del_li_album' href='javascript:;' title='删除'>" + 
			            					"<img src=' " + staticPathVar + "/Admin/images/close1.png'/>" + 
			            				"</a>" + 
			            				"<input type='hidden' name='" + albumfileVarName + "[]' value='" + data.path+"'/>" + 
			            			"</li>";
			            $("#albumUploadList ul").append(li);
			        }
			    	});
			}
			$(function() {
				$(".select1").uedSelect({
					width : 347			  
				});	
				
			    $('.a_del_li_album').live('click', function(){
			    		if (!confirm('确定要删除吗？')){
			    			return;
			    		}
			    		
			    		$(this).parent('li').remove();
			    });
			    
			    
			});
			
		</script>
		
		<script type="text/javascript">
			$(function(){
				showUploadify('listpic');
				
				showAlbumUploadify('albumpic', '<?php echo U("ajaxUpload");?>', 'http://127.0.0.1/vancl/Static', '<?php echo $set['filetype'];?>');
					
				$('form').validate({
					gname: {
						rule: {
							required: true,
							maxlen: 64
						},
						error: {
							required: "商品名称不能为空",
							maxlen: '商品名称不能超过64个字符'
						}
					},
					category_cid: {
						rule: { num:'1,99999' }, error: { num: '请选择商品分类' }
					},
					brand_bid: {
						rule: { num:'1,99999' }, error: { num: '请选择品牌分类' }
					},
					unit: {
						rule: {
							required: true,
							maxlen: 4
						},
						error: {
							required: "单位不能为空",
							maxlen: '单位不能超过4个字符'
						}
					},
					marketprice: {
						rule: { num:'1.00,99999.99' }, error: { num: '库存范围为1.00 ~ 99999.99' }
					},
					shopprice: {
						rule: { num:'1.00,99999.99' }, error: { num: '库存范围为1.00 ~ 99999.99' }
					},
					listpic: {
						rule: {
							required: true,
							maxlen: 60
						},
						error: {
							required: "请选择列表图",
							maxlen: '列表图路径不能超过60个字符'
						}
					}
				});
	
				lastCid = 0;
				$('select[name=category_cid]').change(function(){
					var cid = $(this).val();
					if (lastCid == cid){
						// hdjs的validate也会触发change事件，此时直接返回
						return;
					}
					lastCid = cid;
					
					tid = $(this).find("option:selected").attr('tid');
					$('input[name=type_tid]').val(tid);
					
					$.ajax({
						type:"post",
						url:"<?php echo U('ajaxGetTypeAttr');?>",
						data: {cid:cid },
						dataType: 'json',
						success:function(phpData){
							var attrs = "";
							var specs = "";
							
							$.each(phpData, function(k,v) {
								if (v.taclass == 0){
									// 属性
									attrs += "<li><label>" + v.taname + "</label>" +
											  "<div class='vocation'><select name='gaattrs[" + v.taid + "]' class='select1'>" +
											  "<option value='0' selected>--请选择--</option>";
									$.each(v.tavalue, function(kv, vv) {
										attrs += "<option value='" + vv + "'>" + vv +"</option>";
									});
									attrs += "</select></div></li>";	
								}else{
									// 规格
									specs += "<li taid='" + v.taid + "'><label>" + v.taname + "</label>" +
											 "<div class='vocation'><select name='gaspecs[" + v.taid + "][value][]' class='select1'>" +
											 "<option value='0' selected>--请选择--</option>";
									$.each(v.tavalue, function(kv, vv) {
										specs += "<option value='" + vv + "'>" + vv +"</option>";
									});
									specs += "</select></div>";
									specs += "<div style='float:left'><label>附加价格</label><input name='gaspecs[" + v.taid + "][addedprice][]' type='text' class='dfinput' style='width:200px'/></div>";
									specs += "<div style='padding-left:20px;float:left'><button type='button' class='btn btn-primary btn-block addspec' style='line-height: 0;height: 32px;'>＋ 添加规格</button></div>";
									
								}
							});
							
							$('#goodsattr').html(attrs);
							$('#goodsspec').html(specs);
							$(".select1").uedSelect({
								width : 345			  
							});
						}
					});
					
				})
			});
		</script>
		<script type="text/javascript">
			function showIndexUploadify(varName){
				$('#indexFile').uploadify({
			        'formData': {
			        		//POST数据
			            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			        },
			        'fileTypeDesc' : '上传文件',
			        'fileTypeExts' : '<?php echo $set['filetype'];?>',
			        'swf'      : 'http://127.0.0.1/vancl/Static/uploadify/uploadify.swf',
			        'uploader' : '<?php echo U("ajaxUpload");?>',
			        'buttonText':'选择文件',
			        'fileSizeLimit' : '2000KB',
			        'uploadLimit' : 1,//上传文件数
			        'multi': false,
			        'width':65,
			        'height':25,
			        'successTimeout':10,//等待服务器响应时间
			        'removeTimeout' : 0.2,//成功显示时间
			        'onUploadSuccess' : function(file, data, response) {
			            data=$.parseJSON(data);
			            var imageUrl = data.image?data.url:'http://127.0.0.1/vancl/Static/image/default.png';
			            var li="<li path='"+data.path+"' url='"+data.url+"'>" +
			            				"<img class='img' src='" + imageUrl + "'/>" +
			            				"<a id='a_del_li_indexPic' href='javascript:;' title='删除'>" + 
			            					"<img src='http://127.0.0.1/vancl/Static/Admin/images/close1.png'/>" + 
			            				"</a>" + 
			            				"<input type='hidden' name='indexpic' value='" + data.path+"'/>" + 
			            			"</li>";
			            $("#uploadIndexList ul").prepend(li);
			            $("#uploadIndexDiv").html('');
			            $('#uploadIndexTip').hide();
			        }
			    });
			}
			
			$(function(){
				$('.addspec').live('click', function(){
					var li = $(this).parents('li');
					var taid = li.attr('taid');
					var label = li.children('label').eq(0).html();
					var str = "<li><label>" + label + "</label>";
					var selectObj = li.find('.vocation select');
					str += "<div class='vocation'><select name='gaspecs[" + taid + "][value][]' class='select1'>";
					str += selectObj.html() +"</select></div>";
					str += "<div style='float:left'><label>附加价格</label><input name='gaspecs[" + taid + "][addedprice][]' type='text' class='dfinput' style='width:200px'/></div>";
					str += "<div style='padding-left:20px;float:left'><button type='button' class='btn btn-danger btn-block delspec' style='line-height: 0;height: 32px;'>－ 删除规格</button>";
					str += "</li>";
					li.after(str);
					$(".select1").uedSelect({
						width : 345			  
					});
				});
				
				$('.delspec').live('click',function(){
					if (!confirm("确实要删除该规格吗？")) return;
					
					$(this).parents('li').remove();
				});
				
				$('#a_del_li_indexPic').live('click', function(){
			    		if (!confirm('确定要删除吗？')){
			    			return;
			    		}
			    		$("#uploadIndexList ul li").remove();
			    		var str = "<input id='indexFile' type='file' multiple='true'>";
			
			    		$("#uploadIndexDiv").html(str);
			    		$('#uploadIndexTip').show();
					showIndexUploadify();	
			    });
				showIndexUploadify();
			})
		</script>
	</head>

	<body>
		<div class="place">
			<span>位置：</span>
			<ul class="placeul">
				<li><a href="#">商品管理</a></li>
				<li><a href="#">商品管理</a></li>
				<li><a href="#">添加商品</a></li>
			</ul>
		</div>
		
		<form action="" method="POST">
			<div class="formbody">	
				<div class="formtitle"><span>基本信息</span></div>	
				<ul class="forminfo">
					<li>
						<label>商品名称<b>*</b></label>
						<input name="gname" type="text" class="dfinput" />
					</li>
					<li>
						<label>所属分类<b>*</b></label>  
					    <div class="vocation">
						    <select name="category_cid" class="select1">
						    		<option value="0">--请选择--</option>
						    		<?php foreach ($categoryData as $k=>$v){?>
							    		<option value="<?php echo $v['cid'];?>" tid="<?php echo $v['tid'];?>">    <?php if($v['delimiter']!=''){ ?>|<?php } ?><?php echo $v['delimiter'];?><?php echo $v['cname'];?></option>
						    		<?php }?>
					    		</select>
					    </div>
    					</li>
    					<li>
						<label>所属品牌<b>*</b></label>  
					    <div class="vocation">
						    <select name="brand_bid" class="select1">
						    		<?php foreach ($brandData as $k=>$v){?>
							    		<option value="<?php echo $v['bid'];?>"><?php echo $v['bname'];?></option>
							    <?php }?>
					    		</select>
					    </div>  
    					</li>
    					<li>
						<label>货品编号<b>&nbsp;</b></label>
						<input name="gnumber" type="text" class="dfinput" value="0"/>
					</li>
					<li>
						<label>单位<b>*</b></label>
						<input name="unit" type="text" class="dfinput" />
					</li>
					<li>
						<label>市场价<b>*</b></label>
						<input name="marketprice" type="text" class="dfinput" value="0"/>
					</li>
					<li>
						<label>商城价<b>*</b></label>
						<input name="shopprice" type="text" class="dfinput" value="0"/>
					</li>
					<li>
						<label>点击次数<b>&nbsp;</b></label>
						<input name="click" type="text" class="dfinput" value="0"/>
					</li>
					<li>
						<label>是否推荐</label>
						<cite>
				    			<input name="is_recommend" type="radio" value="0" checked="checked" />&nbsp;否&nbsp;&nbsp;&nbsp;&nbsp;
				    			<input name="is_recommend" type="radio" value="1" />&nbsp;是
				    		</cite>
					</li>
					<li>
						<label>促销宣传语</label>
						<input name="promotes" type="text" class="dfinput" />
					</li>
					<li>
						<label>列表图<b>*</b></label>						
						<div lab="uploadFile" style="float:left">
							<div id="uploadDiv">
				            		<input id="file" type="file" multiple="true">			           		
				            </div>
				            <div id="uploadList">            		
				                <ul>                		
				                </ul>				                
				            </div>
				            <div style="clear: both;"></div>
				        </div>	
				        <div id="uploadTip">
				        		<i>类型: *.jpg,*.png 大小: 2000KB 数量: 1</i>
				        </div>
				        <div style="clear: both;"></div>
					</li>
					<li>
						<label>首页图</label>						
						<div lab="uploadFile" style="float:left">
							<div id="uploadIndexDiv">
				            		<input id="indexFile" type="file" multiple="false">			           		
				            </div>
				            <div id="uploadIndexList">            		
				                <ul>                		
				                </ul>				                
				            </div>
				            <div style="clear: both;"></div>
				        </div>	
				        <div id="uploadIndexTip">
				        		<i>类型: *.jpg,*.png 大小: 2000KB 数量: 1</i>
				        </div>
				        <div style="clear: both;"></div>
					</li>
				</ul>
				
				<div class="formtitle"><span>商品属性</span></div>	
				<ul id="goodsattr" class="forminfo">
					
				</ul>

				<div style="clear: both;"></div>

				<div class="formtitle"><span>商品规格</span></div>	
				<ul id="goodsspec" class="forminfo">
				</ul>
				
				<div style="clear: both;"></div>
				
				<div class="formtitle"><span>商品图册</span></div>	
				<ul class="forminfo">
					<li>
						<label>商品图册<b>*</b></label>  
					   	<div lab="uploadFile" style="float:left">
							<div id="albumUploadDiv">
				            		<input id="albumfile" type="file" multiple="true">			           		
				            </div>				            
				        </div>	
				        <div id="albumUploadTip" class="uploadTip">
				        		<i>类型: *.jpg,*.png 大小: 2000KB 数量: 20</i>
				        </div>
				        <div style="clear: both;"></div>   
    					</li>
    					<li>
    						<label>&nbsp;</label> 
    						<div id="albumUploadList"  class="uploadList" style="float:left">            		
			                <ul>                		
			                </ul>				                
				       	</div>
				        <div style="clear: both;"></div>
    					</li>
				</ul>
				
				<div class="formtitle"><span>描述信息</span></div>
				
				<div id="desc">
					<script id="editor" type="text/plain" style="width:100%;height:500px;" name="description"></script>
				    <script>
				        var ue = UE.getEditor('editor');
				    </script>
			    </div>
			    
				<div style="clear:both;height: 20px;"></div>
			    <button type='submit' class="btn btn-primary btn-block" style="line-height: 0;height: 32px;">确认添加</button>
				
			</div>
			<div style="clear:both;height: 20px;"></div>
			<input type="hidden" name="type_tid" value="" />
			<input type="hidden" name="goods_class_gcid" value="<?php echo $hd['get']['gcid'];?>" />
		</form>
		
	</body>

</html>